// import './lib-tdt/index.js';

import {
  Credit,
  ProviderViewModel,
  WebMapTileServiceImageryProvider,
  UrlTemplateImageryProvider,
  WebMercatorTilingScheme
} from '@cesiumjs';

const tk = '0636865296f6329ada1132448e161ae6';
const tdtUrlSuffix =
  `wmts?service=wmts&request=GetTile&version=1.0.0&LAYER={t}&tileMatrixSet=w&TileMatrix={TileMatrix}&TileRow={TileRow}&TileCol={TileCol}&style=default&format=tiles&tk=${tk}`;
const tdtUrl = 'https://t{s}.tianditu.gov.cn';
const subdomains = ['0', '1', '2', '3', '4', '5', '6', '7'];
const optWebMapTileServiceImageryProviderDefault = {
  layer: 'img',
  style: 'default',
  format: 'tiles',
  // tileMatrixSetID: "GoogleMapsCompatible",//使用谷歌的瓦片切片方式
  tileMatrixSetID: 'w',
  category: '天地图',
  credit: new Credit('天地图全球影像服务'),
  maximumLevel:20,
  subdomains,
  show: false
};

export default {
  tdtImage() {
    return {
      name: "tdtImage",
      title: "天地图影像",
      create: () => new WebMapTileServiceImageryProvider({
        ...optWebMapTileServiceImageryProviderDefault,
        layer: 'tdtImageLayer',
        url: `${tdtUrl}/img_w/${tdtUrlSuffix.replace("{t}","img")}`
      })
    }
  },
  tdtTerrain() {
    return {
      name: "tdtTerrain",
      title: "天地图地形",
      create: () => new WebMapTileServiceImageryProvider({
        ...optWebMapTileServiceImageryProviderDefault,
        url: `${tdtUrl}/ter_w/${tdtUrlSuffix.replace("{t}","ter")}`,
        layer: 'tdtTerrainLayer',
      })
    }
  },
  tdtVector() {
    return {
      name: "tdtVector",
      title: "天地图矢量",
      create: () => new WebMapTileServiceImageryProvider({
        ...optWebMapTileServiceImageryProviderDefault,
        layer: 'tdtVectorLayer',
        url: `${tdtUrl}/vec_w/${tdtUrlSuffix.replace("{t}","vec")}`
      })
    }
  },
  tdtImgAnno() {
    return {
      name: "tdtImgAnno",
      title: "天地图影像注记",
      create: () => new WebMapTileServiceImageryProvider({
        ...optWebMapTileServiceImageryProviderDefault,
        url: `${tdtUrl}/cia_w/${tdtUrlSuffix.replace("{t}","cia")}`,
        layer: 'tdtImgAnnoLayer',
      })
    }
  },
  tdtVecAnno() {
    return {
      name: "tdtVecAnno",
      title: "天地图中文注记",
      create: () => new WebMapTileServiceImageryProvider({
        ...optWebMapTileServiceImageryProviderDefault,
        url: `${tdtUrl}/cva_w/${tdtUrlSuffix.replace("{t}","cva")}`,
        layer: 'tdtVecAnnoLayer',
      })
    }
  },
  tdtVecAnnoEn() {
    return {
      name: "tdtVecAnnoEn",
      title: "天地图英文注记",
      create: () => new WebMapTileServiceImageryProvider({
        ...optWebMapTileServiceImageryProviderDefault,
        url: `${tdtUrl}/eva_w/${tdtUrlSuffix.replace("{t}","eva")}`,
        layer: 'tdtVecAnnoEnLayer',
      })
    }
  },
  tdtTerrainAnno() {
    return {
      name: "tdtTerrainAnno",
      title: "天地图地形注记",
      create: () => new WebMapTileServiceImageryProvider({
        ...optWebMapTileServiceImageryProviderDefault,
        url: `${tdtUrl}/cta_w/${tdtUrlSuffix.replace("{t}","cta")}`,
        layer: 'tdtTerrainAnnoLayer',
      })
    }
  },
  tdtIboMap() { // 叠加国界服务
    return {
      name: "tdtIboMap",
      title: "天地图国界",
      create: () => new UrlTemplateImageryProvider({
        ...optWebMapTileServiceImageryProviderDefault,
        layer: 'tdtIboLayer',
        url: `${tdtUrl}/DataServer?T=ibo_w&x={x}&y={y}&l={z}&tk=${tk}`,
        tilingScheme: new WebMercatorTilingScheme(),
      })
    }
  },
}
